package com.woniu.controller.backpage;

import com.woniu.dao.homePage.UsersDao;
import com.woniu.entity.AdminUser;
import com.woniu.entity.Users;
import com.woniu.entity.WorkUser;
import com.woniu.hander.LoginoutHandler;
import com.woniu.service.backpage.IAdminUserService;
import com.woniu.service.homePage.IUsersService;
import com.woniu.util.RequestParams;
import com.woniu.util.ResData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 刘海山
 * @data 2023/3/4 14:21
 */
@RestController
@RequestMapping("/admin")
public class AdminUserController {

    @Autowired
    IAdminUserService adminUserService;

    @Autowired
    IUsersService iUsersService;

    @Autowired
    RedisTemplate redisTemplate;

    //获取管理员用户数据
    @RequestMapping("getUser")
    public ResData<?> getLoginUserInfo(String username){
        return adminUserService.findUserByUsername(username);
    }

    //插入一条管理员的信息数据
    @RequestMapping("insertAdminUser")
    public ResData<?> insertAdminUser(@RequestBody AdminUser adminUser){
        return adminUserService.insertAdminUser(adminUser);
    }

    //更新一条管理的信息
    @RequestMapping("updateAdminUser")
    public ResData<?> updateAdminUser(@RequestBody AdminUser adminUser){
        return adminUserService.updateAdminUser(adminUser);
    }

    //通过账号查询系统所有的菜单显示
    @RequestMapping("queryAdminMenu")
    public ResData<?> queryMenu(String account){
        return adminUserService.queryMenus(account);
    }

    //对账号进行菜单数据查询和授权
    @RequestMapping("queryMenuAndAuth")
    public ResData<?> getMenuData(Integer userId){
        return adminUserService.queryMenuTreeData(userId);
    }

    //根据用户id删除中间表数据，对数据的重新授权以及改进
    @RequestMapping("adminUserMenus")
    public ResData<?> AdminUserMenus(Integer userId,String menuId){
        ResData<?> menuByUserId = adminUserService.deleteMenuByUserId(userId, menuId);

        return menuByUserId;
    }

    //查询后台列表所有的管理员用户
    @RequestMapping("queryAllUser")
    public ResData<?> queryAllUser(@RequestBody RequestParams<AdminUser> requestParams){
        return adminUserService.queryAllAdminUser(requestParams);
    }

    //修改管理员的状态(启用或禁用)
    @RequestMapping("updateAdminStatus")
    public ResData<?> updateAdminStatus(@RequestBody  AdminUser adminUser){
        return adminUserService.updateAdminStatus(adminUser);
    }

    //查询全部的工作人员列表展示
    @RequestMapping("queryAllWorkUser")
    public ResData<?> queryAllWorkUser(@RequestBody RequestParams<WorkUser> requestParams){
        return adminUserService.queryAllWorkUser(requestParams);
    }

    //添加工作用户人员
    @RequestMapping("insertWorkUser")
    public ResData<?> insertWorkUser(@RequestBody WorkUser workUser){
        return adminUserService.insertWorkUser(workUser);
    }

    //修改工作用户人员的状态(启用或禁用)
    @RequestMapping("updateWorkUserState")
    public ResData<?> updateWorkUserState(@RequestBody  WorkUser workUser){
        return adminUserService.updateWorkUserState(workUser);
    }

    //修改工作人员的信息
    @RequestMapping("updateWorkUserInfo")
    public ResData<?> updateWorkUserInfo(@RequestBody WorkUser workUser){
        return adminUserService.updateWorkUserInfo(workUser);
    }

    //查询用户人员的信息
    @RequestMapping("queryUser")
    public ResData<?> queryUser(@RequestBody RequestParams<Users> requestParams){
        return iUsersService.queryAllUser(requestParams);
    }
}
